/**
 * Created by Freeman on 2016/8/3.
 */
import React, {Component, PropTypes} from 'react'
import Alert from 'react-s-alert'
class Toaster extends Component{
    constructor(props) {
        super(props)

    }
    componentWillReceiveProps(nextProps) {
        const { msg } = nextProps;
        const { hideMsg } = this.props;
        if(msg.content !== '' && msg.type){
            switch(msg.type){
                case 'error':
                    Alert.error(msg.content);
                    break;
                case 'success':
                    Alert.success(msg.content);
                    break;
                case 'info':
                    Alert.info(msg.content);
                    break;
                case 'warning':
                    Alert.warning(msg.content);
                    break;
                default:
                    Alert.error(msg.content)
            }
            hideMsg()
        }
    }


    render() {
        return (
            <div>
                <Alert stack={{limit: 1}} position='top-right' timeout={3000} />
            </div>
        )
    }
}

Toaster.propTypes = {
    hideMsg:PropTypes.func.isRequired
};

export default Toaster;